package cn.bugstack.infrastructure.adapter.repository;


import cn.bugstack.domain.order.adapter.repository.IOrderRepository;
import cn.bugstack.domain.order.model.aggregate.CreateOrderAggregate;
import cn.bugstack.domain.order.model.entity.OrderEntity;
import cn.bugstack.domain.order.model.entity.PayOrderEntity;
import cn.bugstack.domain.order.model.entity.ShopCartEntity;
import cn.bugstack.infrastructure.dao.IOrderDao;
import cn.bugstack.infrastructure.dao.po.PayOrder;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author 丨一
 * @version 1.0
 * @title OrderRepository
 * @description:
 * @date 2024/11/12 20:42
 */

@Repository
public class OrderRepository implements IOrderRepository {
    
    @Resource
    private IOrderDao orderDao;
    
    
    @Override
    public OrderEntity queryUnPayOrder(ShopCartEntity shopCartEntity) {
        return null;
    }

    @Override
    public void updateOrderPayInfo(PayOrderEntity payOrder) {

    }

    @Override
    public void saveOrder(CreateOrderAggregate createOrderAggregate) {
        PayOrder payOrder = PayOrder.builder()
                .userId(createOrderAggregate.getUserId())
                .productId(createOrderAggregate.getProductEntity().getProductId())
                .productName(createOrderAggregate.getProductEntity().getProductName())
                .orderId(createOrderAggregate.getOrderEntity().getOrderId())
                .orderTime(createOrderAggregate.getOrderEntity().getOrderTime())
                .totalAmount(createOrderAggregate.getOrderEntity().getTotalAmount())
                .status(createOrderAggregate.getOrderEntity().getOrderStatusVO().getCode())
                .build();
        orderDao.insert(payOrder);
    }
}
